package com.example.administrator.wallet.adapter;

import android.app.Activity;
import android.graphics.Color;
import android.support.v4.app.FragmentActivity;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.administrator.wallet.R;
import com.example.administrator.wallet.model.bean.DetailsRechargeBean;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

/**
 * Effect:
 * <p>
 * Author:  CaiYapeng
 * <p>
 * Time  :  2018/7/10.
 */
//充值  DetailsRechargeFragment   DetailsRechargeBean
public class DetailsRechargeAdapter extends BaseAdapter {
    private Activity context;
    private List<DetailsRechargeBean.DataBeanX.DataBean> datas;
    private OnClick click;

    public DetailsRechargeAdapter(FragmentActivity activity, List<DetailsRechargeBean.DataBeanX.DataBean> dataBeanList) {
        this.context = activity;
        this.datas = dataBeanList;
    }

    @Override
    public int getCount() {
        return datas == null ? 0 : datas.size();
    }

    @Override
    public Object getItem(int i) {
        return null;
    }

    @Override
    public long getItemId(int i) {
        return 0;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        if (view == null) {
            holder = new ViewHolder();
            view = View.inflate(context, R.layout.item_transaction_record, null);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_currency = (TextView) view.findViewById(R.id.tv_currency);//币种
        holder.tv_currency_money = (TextView) view.findViewById(R.id.tv_currency_money);//金额
        holder.tv_date = (TextView) view.findViewById(R.id.tv_date);//日期
        holder.tx_status = (TextView) view.findViewById(R.id.tv_money);//状态

        holder.tv_currency.setText(datas.get(i).getCoin_symbol());
        holder.tv_currency_money.setText(datas.get(i).getValue_dec());
        holder.tv_date.setText(timedate(datas.get(i).getCreated_at()));


        if ("success".equals(datas.get(i).getTx_status())){
            holder.tx_status.setText(R.string.Recharge_successful);
            holder.tx_status.setTextColor(Color.parseColor("#12a9ed"));
        }else if("fail".equals(datas.get(i).getTx_status())){
            holder.tx_status.setText(R.string.Recharge_failed);
        }else if("pedding".equals(datas.get(i).getTx_status())){
            holder.tx_status.setText(R.string.Recharge_Audit);
            holder.tx_status.setTextColor(Color.parseColor("#ffc107"));
        }
        return view;
    }

    public class ViewHolder {
        private TextView tv_currency;
        private TextView tv_currency_money;
        private TextView tv_date;
        private TextView tx_status;
    }
    /**
     * 调用此方法输入所要转换的时间戳输入例如（1402733340）输出（"2014-06-14  16:09:00"）
     *
     * @param time
     * @return
     */
    public static String timedate(String time) {
        SimpleDateFormat sdr = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        @SuppressWarnings("unused")
        long lcc = Long.valueOf(time);
        int i = Integer.parseInt(time);
        String times = sdr.format(new Date(i * 1000L));
        return times;
    }


    public interface OnClick {
        void Click(DetailsRechargeBean.DataBeanX.DataBean dataBean);
    }

    public void getClickPst(OnClick click) {
        this.click = click;
    }
}
